<?php
/*
 *      dovote.php
 *      
 *      Copyright 2011 unro <unro.ua@gmail.com>
 *      
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 *      
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *      
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 *      MA 02110-1301, USA.
 */
 
include ("../session.php");
include ("../include/core.php");
Openconn();
SelectDB(imwcp);

$tid = trim(mysql_escape_string($_GET['tid']));
settype($tid, "integer");
$uid = $_SESSION["uid"];
$cur_time = GetDataTime();

$selectvv = mysql_query("SELECT * FROM `vote_var` WHERE `topid`='$tid' AND `userid`='$uid'");
$vva_ = mysql_fetch_array($selectvv);

$selectgt = mysql_query("SELECT * FROM `game_top` WHERE `id`='$tid'");
$gta_ = mysql_fetch_array($selectgt);
$vote_link = $gta_["link"];

$vvc = mysql_num_rows($selectvv);
if ($vvc == 0) {
	SelectDB(imwcp);
	mysql_query("INSERT INTO `vote_var` VALUES ('$tid','$uid','$cur_time')");
	SelectDB(auth);
	$bonuses = $gta_['cost'];
	mysql_query("UPDATE `account` SET `bonuses`=bonuses+$bonuses WHERE `id`='$uid'");
	header("Location: $vote_link ");
} else {
	$last_votetime = $vva_['votetime'];
	$time = GetDataTime(gmtime() - 86400);
	if ($last_votetime < $time) {
		SelectDB(imwcp);
		mysql_query("REPLACE INTO `vote_var` VALUES ('$tid','$uid','$cur_time')");
		SelectDB(auth);
		$bonuses = $gta_['cost'];
		mysql_query("UPDATE `account` SET `bonuses`=bonuses+$bonuses WHERE `id`='$uid'");
		header("Location: $vote_link");
	} else {  header("Location: ../index.php"); }
  }
?>